//
//  LGManager.m
//  GameDemo
//
//  Created by Happy on 12/16/16.
//  Copyright © 2016 Happy. All rights reserved.
//

#import "LGManager.h"

@implementation LGManager

static LGManager *manager = nil;
+ (instancetype)sharedInstance {
    if (!manager) {
        manager = [[LGManager alloc] init];
        
        [LGSDKConfigure sharedInstance].isOnline = YES; // 默认线上环境
    }
    
    return manager;
}

- (void)configureServerEnvironment:(BOOL)isOnline {
    [LGSDKConfigure sharedInstance].isOnline = isOnline;
}

- (void)configureWeiXinAppId:(NSString *)appId {
    [WXApi registerApp:appId];
    
    [LGShareManager shareInstance].weiXinAppId = appId;
    [LGLoginManager sharedInstance].weiXinAppId = appId;
    [LGPayManager sharedInstance].weiXinAppId = appId;
}

- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
    return YES;
}
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
    BOOL wxValue = NO;
#if ZBLoginWeiXinIsOpen | ZBShareWeiXinIsOpen
    wxValue = [WXApi handleOpenURL:url delegate:[LGThirdDelegate sharedInstance]];
#endif
    
    BOOL qqValue = NO;
#if ZBLoginQQIsOpen | ZBShareQQIsOpen
    qqValue = [TencentOAuth HandleOpenURL:url];
#endif
    
    BOOL wbValue = NO;
#if ZBLoginWeiBoIsOpen | ZBShareWeiBoIsOpen
//    wbValue = [WeiboSDK handleOpenURL:url delegate:[ZCThirdDelegate sharedInstance]];
#endif
    
#if ZCPayAiBeiIsOpen
    [[IapppayKit sharedInstance] handleOpenUrl:url];
#endif
    
#if ZCPayPingppIsOpen
    [[ZCPaymentManager shareInstance] handlePingppPayResult:url.absoluteString];
#endif
    
    return wxValue | qqValue | wbValue;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
    
    return [self application:application handleOpenURL:url];
}
- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString*, id> *)options {
    
    return [self application:app handleOpenURL:url];
}
@end



@implementation LGManager (Payment)

@end


@implementation LGManager (Login)
- (void)loginInWeiXin:(void(^)(NSError *error, NSDictionary *result))callback {
    [[LGLoginManager sharedInstance] loginInWeiXin:callback];
}
@end


@implementation LGManager (Share)
- (void)share:(LGShareContent *)shareContent shareType:(LGShareType)shareType callback:(void(^)(NSError *error, NSDictionary *result))callback {
    [[LGShareManager shareInstance] share:shareContent shareType:shareType callback:callback];
}
@end
